package com.jy.wms.controller;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.ExportUtils;
import com.jy.wms.common.base.BaseController;
import com.jy.wms.common.base.BaseSessionInfo;
import com.jy.wms.common.base.JsonResult;
import com.jy.wms.pojo.DirectSellingProvincesAndCities;
import com.jy.wms.pojo.SysHz;
import com.jy.wms.pojo.WmsProvinceRankingReport;
import com.jy.wms.service.WmsSupportNumberReportExportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/ExportController")
@Api(value = "/ExportController", description = "直销省市报表导出")
public class WmsSupportNumberReportExportController extends BaseController<WmsSupportNumberReportExportService, WmsProvinceRankingReport> {

    @PostMapping(value = "SelectBathPrimaryExcel")
    @ApiOperation(value = "直销省市排名报表导出", response = JSONObject.class, notes = "直销省市排名报表导出")
    public @ResponseBody
    JsonResult selectbathprimaryexcel(@RequestBody DirectSellingProvincesAndCities ceshi, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception {

        //获取当前操作用户的货主id
        List<SysHz> hz = (List<SysHz>) session.getAttribute(BaseSessionInfo.SessionConsignor);
        String hzid = hz.get(0).getHzid();
        //获取仓库Id
        UserInfo userinfo = (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
        String ckid = userinfo.getUser().getOrgId().get(0).toString();

        ceshi.setCkid(ckid);
        ceshi.setHzid(hzid);

        try {
            String filename = "直销省市排名报表";
            List<WmsProvinceRankingReport> list = null;
            try {
                list = baseService.baseselectbathprimarykeys(ceshi);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("导出："+list);
            ExportUtils reportExcel = new ExportUtils();
            reportExcel.excelExport(list, filename, WmsProvinceRankingReport.class, 1, response, request);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return renderSuccess("导出成功");
    }
}
